﻿Imports CommonLayer
Imports Infragistics.Win.UltraWinToolbars

Public Class ToolEventHandler
    Public Shared Sub ToolBarHandler(ByVal oSender As frmMain, ByVal oItem As ToolBase)
        Dim strTagOK As String = Nothing
        Dim strPermission As Object = Nothing
        If GetTagAndPermission(oItem.Key, strTagOK, strPermission) Then
            If strPermission IsNot Nothing Then
                If _
                    Not _
                    CommonFunction.CheckPermissionByID(CommonFunction.MySession.CurrentUser, strPermission, _
                                                       ActionEnum.Use) Then
                    Return
                End If
            End If
        Else
            strTagOK = oItem.Key
        End If

        Select Case strTagOK
            Case "mnuFile"

            Case "mnuOpenDB"

            Case "mnuCloseDB"

            Case "mnuExit"
                oSender.Close()
            Case "mnuDictionary"

            Case "mnuHelp"

            Case "mnuHelpContent"

            Case "mnuAbout"

            Case "mnuBusiness"

            Case "mnuUtility"

            Case "mnuSystem"

            Case "mnuInformation"

            Case "mnuPrinterConfig"

            Case "mnuReport"

            Case "mnuCreateDB"

            Case "mnuManageDB"

            Case "mnuChangePass"

            Case "mnuUserManagement"
                oSender.ShowMDIClient(frmUserList)
            Case "mnuSearch"

            Case "mnuDBMaintain"

            Case "mnuAccountingObject"
                oSender.ShowMDIClient(frmAccountingObjectList)
            Case "mnuEmpoyee"
                oSender.ShowMDIClient(frmEmployeeList)
            Case "mnuInventoryItemCategory"

            Case "mnuInventoryItem"
                oSender.ShowMDIClient(frmInventoryList)
            Case "mnuStock"
                oSender.ShowMDIClient(frmStock)
            Case "mnuExportData"

            Case "mnuOption"

            Case "mnuDepartment"
                oSender.ShowMDIClient(frmDepartment)
            Case "mnuImportData"

            Case "mnuInward"

            Case "mnuOutward"

            Case "mnuInventoryOpening"

        End Select
    End Sub

    Public Shared Function GetTagAndPermission(ByVal oTag As Object, ByRef stringTag As String, ByRef ePer As Object) _
        As Boolean
        If oTag Is Nothing Then
            Return False
        End If

        Dim strTag As String() = oTag.ToString.Split(";")
        stringTag = strTag(0)

        If strTag.Length = 2 AndAlso strTag(1).Trim <> "" Then
            ePer = CInt(strTag(1).Trim)
        End If

        Return True
    End Function
End Class
